<?php

/**
 * 广告图片
 *
 * Created by PhpStorm.
 * User: evan
 * Date: 16/9/16
 * Time: 上午2:55
 */
class Advert extends MY_Public_Api_Controller
{
    /**
     * 获取广告图片
     */
    public function get()
    {
        $uid    = $this->uid;
        $status = (int)$this->input->get_post('status');
        $page   = (int)$this->input->get_post('page');
        $limit  = (int)$this->input->get_post('limit');


        $this->load->service('common/service_common_advert');
        $data = $this->service_common_advert->get($uid, $status, $page, $limit);


        foreach ($data['data'] as $k => $v)
        {
            unset($data['data'][$k]['audit_uid']);
            unset($data['data'][$k]['audit_uname']);
            unset($data['data'][$k]['audit_opinion']);
            unset($data['data'][$k]['audit_time']);
            unset($data['data'][$k]['ip']);
        }


        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 上传
     */
    public function upload()
    {
        $uid    = $this->uid;
        $fid    = (int)$this->input->get_post('fid');


        $this->load->service('common/service_common_advert');
        $data = $this->service_common_advert->upload($uid, $fid);


        unset($data['data']['ip']);


        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 删除广告
     */
    public function delete()
    {
        $uid = $this->uid;
        $pid = (int)$this->input->get_post('pid');


        $this->load->service('common/service_common_advert');
        $data = $this->service_common_advert->delete($uid, $pid);


        unset($data['data']['ip']);


        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 广告计价
     */
    public function valuation()
    {
        $uid   = $this->uid;
        $pid   = (int)$this->input->get_post('pid');
        $ds_id = (int)$this->input->get_post('ds_id');
        $time  = (int)$this->input->get_post('time');


        $this->load->service('common/service_common_advert_apply');
        $data = $this->service_common_advert_apply->valuation($uid, $pid, $ds_id, $time);


        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 投放广告
     */
    public function apply()
    {
        $uid   = $this->uid;
        $pid   = (int)$this->input->get_post('pid');
        $ds_id = (int)$this->input->get_post('ds_id');
        $time  = (int)$this->input->get_post('time');


        $this->load->service('common/service_common_advert_apply');
        $data = $this->service_common_advert_apply->apply($uid, $pid, $ds_id, $time);


        $this->json_output($data['data'], $data['status']);
    }


    /**
     *
     */
    public function open_advert()
    {
        $this->load->service('common/service_common_advert_apply');
        $data = $this->service_common_advert_apply->open_advert();


        $this->json_output($data['data'], $data['status']);
    }
}